﻿using OS.BLL;
using Swashbuckle.Swagger.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace OS.Web
{

    /// <summary>
    /// 系统类
    /// </summary>
    public class SystemController : ApiController
    {
        public Bll_jbxx_spdaH bllJbxx_spdaH = new Bll_jbxx_spdaH();
        public Bll_zwcl_kczbH bllZwcl_kczbH = new Bll_zwcl_kczbH();

        /// <summary>
        /// 分页获取商品档案列表(允许带条件查询)
        /// 创建人:minjie
        /// 创建时间：2020-09-19
        /// <remarks>
        /// 测试一些内容，不想将无用的东西放在接口名称当中<br/>
        /// 换行输出一下内容
        /// </remarks>
        /// </summary>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="pageNumber">当前页</param>
        /// <param name="strWhere">条件 例如:  spbh='DF03447-081'</param>
        /// <returns></returns>

        [HttpGet]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(jbxx_spdaH_Entity))]
        public RestPage<jbxx_spdaH_Entity> GetSpdaList(int pageSize, int pageNumber, string strWhere)
        {
             RestPage<jbxx_spdaH_Entity> dto = new RestPage<jbxx_spdaH_Entity>();
            if (strWhere==null|| !Common2.CheckBadWord(strWhere))
            {
                dto.status = 1;
                int startIndex = (pageNumber - 1) * pageSize + 1;
                int endIndex = pageNumber * pageSize;
                List<jbxx_spdaH_Entity> ls = bllJbxx_spdaH.GetModelList(strWhere, "xgsj desc", startIndex, endIndex);
                int count = bllJbxx_spdaH.GetRecordCount(strWhere);
                dto.rows = ls;
                dto.total = count;
            }
            else
            {
                dto.status = 0;
                dto.msg = "条件存在sql注入风险 不允许操作！";
            }

            return dto;
        }
        /// <summary>
        /// 分页获取商品档案列表 
        /// 创建人:minjie
        /// 创建时间：2020-09-19
        /// </summary>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="pageNumber">当前页</param>
        /// <returns></returns>
        [HttpGet]
        public RestPage<jbxx_spdaH_Entity> GetSpdaList_1(int pageSize, int pageNumber)
        {
             string strWhere="";
            RestPage<jbxx_spdaH_Entity> dto = new RestPage<jbxx_spdaH_Entity>();
            if (!Common2.CheckBadWord(strWhere))
            {
                dto.status = 1;
                int startIndex = (pageNumber - 1) * pageSize + 1;
                int endIndex = pageNumber * pageSize;
                List<jbxx_spdaH_Entity> ls = bllJbxx_spdaH.GetModelList(strWhere, "xgsj desc", startIndex, endIndex);
                int count = bllJbxx_spdaH.GetRecordCount(strWhere);
                dto.rows = ls;
                dto.total = count;
            }
            else
            {
                dto.status = 0;
                dto.msg = "条件存在sql注入风险 不允许操作！";
            }

            return dto;
        }


        /// <summary>
        /// 分页获取库存列表（允许带条件）
        /// 创建人:minjie
        /// 创建时间：2020-09-19
        /// </summary>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="pageNumber">当前页</param>
        /// <param name="strWhere">条件</param>
        /// <returns></returns>
        [HttpGet]
        public RestPage<zwcl_kczbH_Entity> GetKczbList(int pageSize, int pageNumber, string strWhere)
        {
            RestPage<zwcl_kczbH_Entity> dto = new RestPage<zwcl_kczbH_Entity>();
            if (!Common2.CheckBadWord(strWhere))
            {
                dto.status = 1;
                int startIndex = (pageNumber - 1) * pageSize + 1;
                int endIndex = pageNumber * pageSize;
                List<zwcl_kczbH_Entity> ls = bllZwcl_kczbH.GetModelList("", "DjLsh desc", startIndex, endIndex);
                int count = bllJbxx_spdaH.GetRecordCount("");
                dto.rows = ls;
                dto.total = count;
            }
            else
            {
                dto.status = 0;
                dto.msg = "条件存在sql注入风险 不允许操作！";
            }

            return dto;
        }
        /// <summary>
        /// 分页获取库存列表(允许带条件)
        /// 创建人:minjie
        /// 创建时间：2020-09-19
        /// </summary>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="pageNumber">当前页</param>
        /// <param name="strWhere">条件</param>
        /// <returns></returns>
        [HttpGet]
        public RestPage<zwcl_kczbH_Entity> GetKczbListBySpbh(int pageSize, int pageNumber, string strWhere)
        {
            RestPage<zwcl_kczbH_Entity> dto = new RestPage<zwcl_kczbH_Entity>();
            if (!Common2.CheckBadWord(strWhere))
            {
                dto.status = 1;
                int startIndex = (pageNumber - 1) * pageSize + 1;
                int endIndex = pageNumber * pageSize;
                List<zwcl_kczbH_Entity> ls = bllZwcl_kczbH.GetModelList("", "DjLsh desc", startIndex, endIndex);
                int count = bllJbxx_spdaH.GetRecordCount("");
                dto.rows = ls;
                dto.total = count;
            }
            else
            {
                dto.status = 0;
                dto.msg = "条件存在sql注入风险 不允许操作！";
            }
            return dto;
        }
        /// <summary>
        /// 单独获取商品库存
        /// 创建人:minjie
        /// 创建时间：2020-09-19
        /// </summary>
        /// <param name="yy">年</param>
        /// <param name="mm">月</param>
        /// <param name="ckbh">仓库编号</param>
        /// <param name="spbh">商品编号</param>
        /// <returns></returns>
        [HttpGet]
        public Rest<zwcl_kczbH_Entity> GetKczbListByWhere(int yy, int mm, string ckbh, string spbh)
        {
            Rest<zwcl_kczbH_Entity> dto = new Rest<zwcl_kczbH_Entity>();
            string strWhere = "1=1 ";
            if (yy > 0)
                strWhere += " and yy=" + yy;
            if (mm > 0)
                strWhere += " and mm=" + mm;
            if (ckbh != null && ckbh != "")
                strWhere += " and ckbh='" + ckbh + "'";
            if (spbh != null && spbh != "")
                strWhere += " and spbh='" + spbh + "'";
            List<zwcl_kczbH_Entity> ls = bllZwcl_kczbH.GetModelList(strWhere);
            if (ls != null && ls.Count > 0)
            {
                dto.status = 1;
                dto.model = ls[0];
            }
            else
            {
                dto.status = 0;
                dto.msg = "无法查询到该记录";
            }
            return dto;
        }



    }
}
